package com.flag.liutao.common.config;

import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;


/**
 * program:  hqmis
 * ClassName:  RedisTemplateConfig
 * create:  2022-09-14 10:02
 * describe:
 *
 * @author: lin
 * @since： JDK1.8
 **/
@Configuration
//@EnableCaching
public class RedisTemplateConfig extends CachingConfigurerSupport {

	  @Bean
	  public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
			System.out.println("--进入redis--");
			RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
			redisTemplate.setConnectionFactory(factory);

			FastJsonRedisSerializer<Object> fastJsonRedisSerializer = new FastJsonRedisSerializer<Object>(Object.class);

			// 设置值（value）的序列化采用FastJsonRedisSerializer。
			redisTemplate.setValueSerializer(fastJsonRedisSerializer);
			redisTemplate.setHashValueSerializer(fastJsonRedisSerializer);
			// 设置键（key）的序列化采用StringRedisSerializer。
			redisTemplate.setKeySerializer(new StringRedisSerializer());
			redisTemplate.setHashKeySerializer(new StringRedisSerializer());

			redisTemplate.afterPropertiesSet();
			return redisTemplate;
	  }


}

